package ms.platform.progress.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import ms.platform.plan.dto.FactoryDto;
import ms.platform.plan.dto.TargetDto;
import ms.platform.plan.service.BusModelService;
import ms.platform.progress.dto.ModelPlanDto;
import ms.platform.progress.service.ProgressViewService;
import ms.platform.util.DateUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/bus/screen/")
public class LargeScreenController {
	@Autowired
	ProgressViewService progressViewService;
	@Autowired
	BusModelService busModelService;
	
	/*@RequestMapping(value = "/showScreen")
	public String showScreen(@RequestParam Map<String,Object> map, HttpServletRequest request){
		map.put("startDate", DateUtil.getPreviousDate(new Date(),6,"yyyy-MM-dd"));
		map.put("endDate", DateUtil.getAfterDate(new Date(), 7, "yyyy-MM-dd"));
		map.put("pageSize", 9);
		List<ModelPlanDto> list = new ArrayList<>();
		if(map.size() > 0){
			list = progressViewService.queryAllModelPlan(map,request);
			if(list.size()==0){
				request.setAttribute("page", 0);
				map.put("page", 1);
				list = progressViewService.queryAllModelPlan(map,request);
			}else{
				System.err.println(map.get("page"));
				request.setAttribute("page", map.get("page")==null?0:map.get("page"));
			}
		}
		request.setAttribute("list", list);
		SimpleDateFormat df = new SimpleDateFormat("MM-dd");//设置日期格式 客户要求当天用红色标注
		String date = df.format(new Date());//获取当天时间
		request.setAttribute("newDate", date);
		List<FactoryDto> factoryList = busModelService.queryAllFactory("F");
		request.setAttribute("factoryList", factoryList);
		if(list.size() > 0 && list.get(0).getItems().size() > 0){
			request.setAttribute("cloumns", list.get(0).getItems());
			request.setAttribute("size", list.get(0).getItems().size());
		}
		return "largeScreen/largeScreen";
	}*/
	
	@RequestMapping(value = "/showScreen")
	public String showScreen(@RequestParam Map<String,Object> map, HttpServletRequest request){
		map.put("startDate", DateUtil.getPreviousDate(new Date(),6,"yyyy-MM-dd"));
		map.put("endDate", DateUtil.getAfterDate(new Date(), 7, "yyyy-MM-dd"));
		map.put("pageSize", 5);
		List<ModelPlanDto> list = new ArrayList<>();
		if(map.size() > 0){
			list = progressViewService.queryAllModelPlan(map,request);
		}
		request.setAttribute("list", list);
		SimpleDateFormat df = new SimpleDateFormat("MM-dd");//设置日期格式 客户要求当天用红色标注
		String date = df.format(new Date());//获取当天时间
		request.setAttribute("newDate", date);
		List<FactoryDto> factoryList = busModelService.queryAllFactory("F");
		request.setAttribute("factoryList", factoryList);
		List<TargetDto> mTypeList = busModelService.queryAllmodelType();
        request.setAttribute("mTypeList", mTypeList);
		if(list.size() > 0 && list.get(0).getItems().size() > 0){
			request.setAttribute("cloumns", list.get(0).getItems());
			request.setAttribute("size", list.get(0).getItems().size());
		}
		return "largeScreen/largeScreen";
	}
}
